package com.mexico.inloancash.adapter;


import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mexico.inloancash.R;
import com.mexico.inloancash.activity.IndiaWebViewActivity;
import com.mexico.inloancash.bean.India_Billing_ListBean;
import com.mexico.inloancash.utils.MyPreferencesManager;

import java.text.SimpleDateFormat;


public class IndiaBillAccountAdapter extends BaseQuickAdapter<India_Billing_ListBean.DataBean, BaseViewHolder> {

    public IndiaBillAccountAdapter() {
        this(R.layout.india_activity_auth_view_layout_item);
    }

    public IndiaBillAccountAdapter(int layoutResId) {
        super(layoutResId);
    }

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    protected void convert(BaseViewHolder helper, final India_Billing_ListBean.DataBean item) {
        try {
            if (!TextUtils.isEmpty(item.getAmount())) {
                //helper.setText(R.id.all_count, FormatTosepara.formatTosepara(Integer.parseInt(item.getAmount().split("\\.")[0])));
                //helper.setText(R.id.loan_money, FormatTosepara.formatTosepara(Integer.parseInt(item.getAmount().split("\\.")[0])));

                helper.setText(R.id.all_count,item.getPay_amount());
                helper.setText(R.id.loan_money,item.getPay_amount());
            }

            //"status": 0, //0-待审核，1-通过，2-拒绝，4-已放款，5-已逾期，7-延期

            if (item.getStatus() == 2) {
                TextView status = helper.getView(R.id.status);
//                status.setBackgroundResource(R.drawable.india_bill_text_jump_back2);
                status.setBackgroundResource(R.drawable.india_bill_status_jump_red);
                status.setText("Has been rejected");//已被拒绝
//                status.setTextColor(Color.parseColor("#A2A5AC"));
                helper.getView(R.id.pay_money_button).setVisibility(View.GONE);
            } else if (item.getStatus() == 6) {
                TextView status = helper.getView(R.id.status);
//                status.setBackgroundResource(R.drawable.india_bill_text_jump_back3);
                status.setBackgroundResource(R.drawable.india_bill_status_jump_gray);
                //status.setText("sudah dilunasi");
                status.setText("Complete repayment");//已还款
//                status.setTextColor(Color.parseColor("#A2A5AC"));
                helper.getView(R.id.pay_money_button).setVisibility(View.GONE);
            } else if (item.getStatus() == 5) {
                TextView status = helper.getView(R.id.status);
//                status.setBackgroundResource(R.drawable.india_bill_text_jump_back2);
                status.setBackgroundResource(R.drawable.india_bill_status_jump_red);
                //status.setText("Terlambat");
                status.setText("Overdue");//已逾期
//                status.setTextColor(Color.parseColor("#FF0F06"));
                helper.getView(R.id.pay_money_button).setVisibility(View.VISIBLE);
            } else {
                TextView status = helper.getView(R.id.status);
//                status.setBackgroundResource(R.drawable.jump_bill_text_back1);
                status.setBackgroundResource(R.drawable.india_bill_status_jump_green);
                //status.setText("proses pelunasan");
                status.setText("Bill");
//                status.setTextColor(Color.parseColor("#3C8DF6"));
                helper.getView(R.id.pay_money_button).setVisibility(View.VISIBLE);
            }

            //reply_date 还款日期
            //review_date 申请日期

            helper.setText(R.id.review_date, sdf.format(Long.valueOf(item.getAddtime() + "000")));

            if (item.getDelay_time() > 0) {
                helper.setText(R.id.reply_date, sdf.format(Long.valueOf(item.getDelay_time() + "000")));
            } else if (item.getDelay_time() == 0 && item.getDeadline() == 0) {
                helper.getView(R.id.time_relative).setVisibility(View.GONE);
            } else {
                helper.setText(R.id.reply_date, sdf.format(Long.valueOf(item.getDeadline() + "000")));
            }
            helper.getView(R.id.pay_money_button).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent web = new Intent(mContext, IndiaWebViewActivity.class);
                    web.putExtra("web", MyPreferencesManager.getString("payweb", ""));
                    web.putExtra("type", 2);//拒绝后跳转的H5
                    web.putExtra("orderno", item.getOrderno());
                    mContext.startActivity(web);
                }
            });
        } catch (Exception e) {

        }
    }
}
